import request from '@/util/request'
import {Toast} from 'vant'
import store from '../store';
import router from '../router'
const hasTokenRequest = (req) => {
    if (store.getters.address) {
        req.data.address = store.getters.address
    } else {
        store.commit('LOGOUT')
        router.replace({
            path: '/connect'
        })
    }
    //req.data.address = '0x1b6F13Ca297aD87EAfc516556d48fc51Ea41596f'
    return request({
        url: req.url,
        data: req.data,
        method: req.method
    })
}
const noTokenRequest = (req) => {
    return request({
        url: req.url,
        data: req.data,
        method: req.method
    })
}
// 获取总算力、个人算力
export function getTotalHashRateData(data) {
    return noTokenRequest({
        url:'/api/index/getTotalHashRateData',
        data,
        method:'post'
    })
}


// 登录
export function toLogin(data) {
    return noTokenRequest({
        url:'/api/users/register',
        data:data,
        method:'post'
    })
}


// 获取我的算力
export function getMyNftHashRateData(data) {
    return hasTokenRequest({
        url:'/api/nft/myNftHashRateData',
        data:data,
        method:'post'
    })
}

// 获取算力池
export function getPoolData(data) {
    return hasTokenRequest({
        url:'/api/index/loggedIngInData',
        data:data,
        method:'post'
    })
}

// 质押单个
export function pledgeNftOne(data) {
    return hasTokenRequest({
        url:'/api/nft/pledgeNft',
        data:data,
        method:'post'
    })
}

// 领取收益
export function receiveNft(data) {
    return hasTokenRequest({
        url:'/api/nft/receiveNftEarnData',
        data:data,
        method:'post'
    })
}


// LP池质押
export function ZYpledgeLp(data) {
    return hasTokenRequest({
        url:'/api/lp/pledgeLp',
        data:data,
        method:'post'
    })
}

// 赎回
export function onRedemptionLp(data) {
    return hasTokenRequest({
        url:'/api/lp/redemptionLp',
        data:data,
        method:'post'
    })
}

// 领取收益
export function onReceiveLpEarnData(data) {
    return hasTokenRequest({
        url:'/api/lp/receiveLpEarnData',
        data:data,
        method:'post'
    })
}

// 创世款模型
export function getMyNftListByOriginNft(data) {
    return hasTokenRequest({
        url:'/api/nft/myNftListByOriginNftData',
        data:data,
        method:'post'
    })
}

// 铸造算力NFT
export function zMake(data) {
    return hasTokenRequest({
        url:'/api/nft/castingNft',
        data:data,
        method:'post'
    })
}


// 可寄售NFT列表
export function myNftListByBuyList(data) {
    return hasTokenRequest({
        url:'/api/nft/myNftListByPledgeData',
        data:data,
        method:'post'
    })
}

// 已质押NFT
export function ZYNFTList(data) {
    return hasTokenRequest({
        url:'/api/nft/myNftListByUserdPledgeData',
        data:data,
        method:'post'
    })
}

// 刷新
export function reflushNFT(data) {
    return hasTokenRequest({
        url:'/api/nft/refreshNftData',
        data:data,
        method:'post'
    })
}

// 寄售
export function saleService(data) {
    return hasTokenRequest({
        url:'/api/nft/shelvesNftData',
        data:data,
        method:'post'
    })
}

// NFT质押，根据编号质押
export function toPledgeNft(data) {
    return hasTokenRequest({
        url:'/api/nft/pledgeNft',
        data:data,
        method:'post'
    })
}


// 我的寄售
export function myNftJSListData(data) {
    return hasTokenRequest({
        url:'/api/nft/myNftListData',
        data:data,
        method:'post'
    })
}

// 寄售市场
export function nftListDataMarkets(data) {
    return hasTokenRequest({
        url:'/api/nft/nftListData',
        data:data,
        method:'post'
    })
}

// 购买
export function buyNftModel(data) {
    return hasTokenRequest({
        url:'/api/nft/buyNftData',
        data:data,
        method:'post'
    })
}


// 下架
export function toUnshelvesNftData(data) {
    return hasTokenRequest({
        url:'/api/nft/unshelvesNftData',
        data:data,
        method:'post'
    })
}


// 获取铸造需要支付的价格
export function toGetCastingPrice(data) {
    return hasTokenRequest({
        url:'/api/nft/getCastingPrice',
        data:data,
        method:'post'
    })
}

// 获取邀请码
export function toGetInvite(data) {
    return hasTokenRequest({
        url:'/api/users/getUserInviteInfo',
        data:data,
        method:'post'
    })
}

// 绑定邀请码
export function toBindInviteCode(data) {
    return hasTokenRequest({
        url:'/api/users/bindInviteCode',
        data:data,
        method:'post'
    })
}


// 获取正在交易中的记录
export function getTransferLogData(data) {
    return hasTokenRequest({
        url:'/api/index/getTransferLogData',
        data:data,
        method:'post'
    })
}
